package com.bjdd.jdy.ui.feedback;

import com.bjdd.jdy.entity.FeedBack;
import com.bjdd.jdy.util.JumpUtil;
import com.bjdd.jdy.util.L;
import com.bjdd.jdy.util.SpUtil;
import com.bjdd.jdy.util.T;

/**
 * Created by Administrator on 2017/5/9.
 */

public class FeedBackPresenter extends FeedBackContract.Presenter {
    @Override
    public void onStart() {
        if (SpUtil.getUser() == null || SpUtil.getUser().equals("") || SpUtil.getUser().getCarrierId() == null) {
            JumpUtil.toLogin(context);
            return;
        }
    }

    @Override
    void feedBack(FeedBack feedBack, String content) {
        showLoadingDialog(false);
        String token = SpUtil.getToken();
        String userId = SpUtil.getUser().getCarrierId();
        rxManager.add(model.feedBack(token,feedBack,content,userId)
        .subscribe(result -> {
            hideLoadingDialog();
            if (!result.isError()){
                view.feedBackSuccess();
            }else {
                T.show(result.getMsg());
            }
        },e -> {
            hideLoadingDialog();
            T.show("提交失败");
            L.d("错误："+e.getMessage());
        }));
    }
}
